@layout("/common/_container.html"){
<div class="row">
    <div class="col-sm-12" id="firmwareuploadpage">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>上传固件</h5>
            </div>
            <div class="ibox-content">
                //自定义内容

                <h1>文件上传</h1>
                <form action="/firmware/fileUpload" method="post" enctype="multipart/form-data">
                    <p>选择文件: <input type="file" name="fileName"/></p>
                    <p><input type="submit" value="提交"/></p>
                </form>
                <p>选择excel文件: <input type="file" id="open-excel" /></p>
                <p id="content"></p>

                <script>

                    $('#open-excel').change(function(e) {
                        var files = e.target.files;
                        var fileReader = new FileReader();
                        fileReader.onload = function (ev) {
                            try {
                                var data = ev.target.result,
                                    workbook = XLSX.read(data, {
                                        type: 'binary'
                                    }),
                                    values = []; // 存储获取到的数据
                                console.log('存储获取到的数据');
                            } catch (e) {
                                console.log('文件类型不正确');
                                return;
                            }

                            // 遍历每张表读取
                            for (var sheet in workbook.Sheets) {
                                console.log('遍历每张表读取');
                                if (workbook.Sheets.hasOwnProperty(sheet)) {
                                    values = values.concat(XLSX.utils.sheet_to_json(workbook.Sheets[sheet]));
                                    //break; // 如果只取第一张表，就取消注释这行
                                }
                            }
                            // console.log(values);
                            for(var i=0;i<values.length;i++){
                                console.log(values[i]);
                                var str1=JSON.stringify(values[i]);
                                $('#content').html($('#content').text()+"<br/>"+str1);
                            }

                        }
                        // 以二进制方式打开文件
                        fileReader.readAsBinaryString(files[0]);
                    });
                </script>
            </div>
        </div>
    </div>
</div>
<script src="${ctxPath}/assets/common/plugins/jquery/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/xlsx/0.11.9/xlsx.core.min.js"></script>

@}
